package com.weixing.mall.provider.config;

import com.weixing.mall.core.config.ErrorPageConfig;
import com.weixing.mall.core.config.SwaggerConfiguration;
import com.weixing.mall.core.config.WeiXingCoreConfig;
import com.weixing.mall.core.converter.EnumConvertFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @Author: kfc
 * @Description: <br/>
 * Date:Create in 2019/7/24 15:01
 * @Modified By:
 */
@Configuration
@Import({SwaggerConfiguration.class,
        WeiXingCoreConfig.class,
        ErrorPageConfig.class})
public class UaaWebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private  EnumConvertFactory enumConvertFactory;
    /**
     * 19      * 发现如果继承了WebMvcConfigurationSupport，则在yml中配置的相关内容会失效。
     * 20      * 需要重新指定静态资源
     * 21      * @param registry
     * 22
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
//        super.addResourceHandlers(registry);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(enumConvertFactory);
    }

}
